import ACCESS_ENUM from '@/access/accessEnum.ts'



const checkAccess = (loginUser: any, needAccess= ACCESS_ENUM.NOT_LOGIN)=>{
  //获取当前登录用户权限
  const loginUserAccess = loginUser?.userRole ?? ACCESS_ENUM.NOT_LOGIN;
  if (needAccess === ACCESS_ENUM.NOT_LOGIN) {
    return true;
  }
  //登录才能访问
  if(needAccess === ACCESS_ENUM.USER){
    if (loginUserAccess === ACCESS_ENUM.NOT_LOGIN) {
      return false;
    }
  }
  //管理员才能访问
  if(needAccess === ACCESS_ENUM.ADMIN){
    if (loginUserAccess !== ACCESS_ENUM.ADMIN) {
      return false;
    }
  }
  return true;
};

export default checkAccess;
